package com.socket.nio.nio.bytebuf;

import com.socket.nio.nio.util.ByteBufPrinter;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

/**
 * @author Hexudong
 * @date 2025/4/12
 */
public class ByteBufWrite {
  public static void main(String[] args) {
    ByteBuf buf = Unpooled.buffer(16);

    // 基本写入
    buf.writeByte(0x01);                 // 写入1字节
    buf.writeShort(0x0203);              // 写入2字节
    buf.writeInt(0x04050607);            // 写入4字节
    buf.writeLong(0x08090A0B0C0D0E0FL);  // 写入8字节
    ByteBufPrinter.prettyPrint(buf);

    byte[] bytes = {0x10, 0x11, 0x12};
    buf.writeBytes(bytes); // 写入字节数组
    ByteBufPrinter.prettyPrint(buf); // 发生扩容 容量=64
  }
}
